﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Zyg.Security;
using Zyg.SSO.Core;

namespace logintest
{
    public partial class login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["Userinfo"] != null || Request.QueryString["Ticket"] != null)
            {
                string struserinfo = Request.QueryString["Userinfo"].ToString();
                string strTicket = Request.QueryString["Ticket"].ToString();

                SecurityHelper shelper = new SecurityHelper();
                struserinfo = shelper.Decrypt(struserinfo, EncryptionAlgorithm.Des);

                APUserInfo userinfo = APUserInfo.DeSerialize(struserinfo);

                string asUrl = System.Configuration.ConfigurationManager.AppSettings["ASWebServiceUrl"];
                string asNamespace = System.Configuration.ConfigurationManager.AppSettings["ASWebServiceNamespace"];
                string asClassName = System.Configuration.ConfigurationManager.AppSettings["ASWebServiceClassName"];

                string myId = "f7b18e6d-95b1-4d1d-8eef-8a31db397dcc";
                string requestIP = Request.UserHostAddress;

                bool valid = (bool)Zyg.Utility.WebServiceUtility.TryWebService(asUrl, asNamespace, asClassName, "LegitimateTicket", myId, requestIP, strTicket);

                if (valid)
                {
                    Response.Write(string.Format("<div style='color: #009900;'>SSO登录成功</div><br />用户名为:{0}<br />密码为:{1}", userinfo.UserName, userinfo.PassWord));
                }
                else
                {
                    Response.Write(string.Format("<div style='color: #ff0000;'>SSO登录失败</div><br />用户名: {0}", userinfo.UserName));
                }
            }
            else
            {
                Response.Write("<div style='color: #ff0000;'>SSO登录失败,未提交用户信息</div>");
            }
        }
    }
}
